package com.lhb.user.utils;

import java.util.Random;

public class RandomGenerator {

    private static final String randomNameTemplate = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+,./?;:'\"{}[]\\|-=";
    private static final int NAME_LENGTH = 16;
    //生成随机姓名
    public static String generateRandomName() {
        Random random = new Random();
        StringBuilder name = new StringBuilder(NAME_LENGTH);
        for(int i=0;i<NAME_LENGTH;i++)
        {
            int index = random.nextInt(randomNameTemplate.length());
            name.append(randomNameTemplate.charAt(index));
        }
        return name.toString();
    }

    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+";
    private static final int PASSWORD_LENGTH = 12;
    //生成随机密码
    public static String generateRandomPassword() {
        Random random = new Random();
        StringBuilder password = new StringBuilder(PASSWORD_LENGTH);

        for (int i = 0; i < PASSWORD_LENGTH; i++) {
            int index = random.nextInt(CHARACTERS.length());
            password.append(CHARACTERS.charAt(index));
        }

        return password.toString();
    }
    //生成随机验证码
    public static String generateCode(int length)
    {
        Random random = new Random();
        StringBuilder stringBuilder = new StringBuilder();
        for(int i=0;i<length;i++)
        {
            stringBuilder.append(random.nextInt(10));
        }
        return stringBuilder.toString();
    }
}